﻿using System;
using System.Collections.Generic;
using System.Text;

namespace GMusicBox.Core
{
    public class MusicDownloadTask
    {
        public string id;
        public string saveto;
        public string iscomplete = "False";
        public DateTime completeDate = new DateTime();
        public Song Song;

        string beganWrite = null;
        public void BeginWrite(string name)
        {
            beganWrite = name;
        }

        public void WriteBegan(string value)
        {
            if (beganWrite == null) return;
            if (beganWrite == "id") id = value;
            else if (beganWrite == "saveto") saveto = value;
            else if (beganWrite == "iscomplete") iscomplete = value;
            else if (beganWrite == "completeDate") completeDate = DateTime.Parse(value);
            beganWrite = null;
        }

        public string ToXML(int Indent)
        {
            string indent = "";
            string body = "";
            for (int i = 0; i < Indent; i++) indent += "\t";
            body += indent + "<download>\r\n"; indent += "\t";
            body += string.Format("{0}<id>{1}</id>\r\n", indent, id);
            body += string.Format("{0}<saveto>{1}</saveto>\r\n", indent, saveto);
            body += string.Format("{0}<iscomplete>{1}</iscomplete>\r\n", indent, iscomplete);
            body += string.Format("{0}<completeDate>{1}</completeDate>\r\n", indent, completeDate.ToString());
            body += indent.Substring(0, indent.Length - 1) + "</download>\r\n";
            return body;
        }
    }
}
